Imports System.Windows.Forms

Public Class frmMain

    Private m_ChildFormNumber As Integer

    Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        ' Create a new instance of the child form.
        Dim ChildForm As System.Windows.Forms.Form = New frmSettings
        ' Make it a child of this MDI form before showing it.
        ChildForm.MdiParent = Me

        ChildForm.Show()

    End Sub

    Private Sub CleanupForm(ByVal sender As Object, ByVal e As EventArgs) Handles mnuUsersStaleAccounts.Click
        SpawnChildForm(New frmCleanup)
    End Sub

    Private Sub HierarchyEditing(ByVal sender As Object, ByVal e As EventArgs) Handles mnuUsersHierarchy.Click
        SpawnChildForm(New frmHierarchy)
    End Sub

    Private Sub ExitToolsStripMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs) Handles mnuApplicationExit.Click
        Me.Close()
    End Sub

    Private Sub StatusBarToolStripMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs) Handles StatusBarToolStripMenuItem.Click
        Me.StatusStrip.Visible = Me.StatusBarToolStripMenuItem.Checked
    End Sub

    Private Sub CascadeToolStripMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs) Handles CascadeToolStripMenuItem.Click
        Me.LayoutMdi(MdiLayout.Cascade)
    End Sub

    Private Sub TileVerticleToolStripMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs) Handles TileVerticalToolStripMenuItem.Click
        Me.LayoutMdi(MdiLayout.TileVertical)
    End Sub

    Private Sub TileHorizontalToolStripMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs) Handles TileHorizontalToolStripMenuItem.Click
        Me.LayoutMdi(MdiLayout.TileHorizontal)
    End Sub

    Private Sub ArrangeIconsToolStripMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs) Handles ArrangeIconsToolStripMenuItem.Click
        Me.LayoutMdi(MdiLayout.ArrangeIcons)
    End Sub

    Private Sub CloseAllToolStripMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs) Handles CloseAllToolStripMenuItem.Click
        ' Close all child forms of the parent.
        For Each ChildForm As Form In Me.MdiChildren
            ChildForm.Close()
        Next
    End Sub

    Private Sub OptionsToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OptionsToolStripMenuItem.Click

        ' Create a new instance of the child form.
        Dim ChildForm As System.Windows.Forms.Form = New frmSettings
        ' Make it a child of this MDI form before showing it.
        ChildForm.MdiParent = Me

        ChildForm.Show()

    End Sub

    Private Sub AttributeCleanupToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuUsersAttributeCleanup.Click
        SpawnChildForm(New frmAttributeCleanup)
    End Sub

    Private Sub HelpToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles _
        ContentsToolStripMenuItem.Click, IndexToolStripMenuItem.Click, SearchToolStripMenuItem.Click
        MessageBox.Show("Help is pending implementation")
    End Sub

    Private Sub AboutToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AboutToolStripMenuItem.Click
        ' Create a new instance of the child form.
        Dim ChildForm As System.Windows.Forms.Form = New AboutBox1
        ' Make it a child of this MDI form before showing it.
        ChildForm.MdiParent = Me

        ChildForm.Show()
    End Sub

    Private Sub AdHocViewToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuUsersAdHocView.Click
        SpawnChildForm(New frmAdHoc)
    End Sub

    Private Sub mnuComputersStaleComputers_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuComputersStaleComputers.Click
        SpawnChildForm(New frmComputerCleanup)
    End Sub

    Private Sub mnuComputersHierarchy_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuComputersHierarchy.Click
        SpawnChildForm(New frmComputerHierarchy)
    End Sub

    Private Sub mnuComputersAttributeCleanup_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuComputersAttributeCleanup.Click
        SpawnChildForm(New frmComputerAttributeCleanup)
    End Sub

    Private Sub mnuComputersAdHocView_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuComputersAdHocView.Click
        SpawnChildForm(New frmComputerAdHoc)
    End Sub

    Private Sub DelegatesToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DelegatesToolStripMenuItem.Click
        SpawnChildForm(New frmDelegates)
    End Sub

    Private Sub SpawnChildForm(ByVal ChildForm As Form)
        ' Make it a child of this MDI form before showing it.
        ChildForm.MdiParent = Me

        m_ChildFormNumber += 1
        ChildForm.Text = ChildForm.Text & "(Window " & m_ChildFormNumber & ")"

        ChildForm.Show()
    End Sub
End Class
